<template>
	<view>
		<myhead left="1"></myhead>
		<view class="tit">{{lxTxt}}</view>
		<block v-if="lx==1">
			<input placeholder="请输入要修改昵称" v-model="txt1"></input>
		</block>
		<block v-if="lx==2">
			<input placeholder="请输入登录密码" password v-model="txt2"></input>
			<input placeholder="请输入新密码" password v-model="txt3"></input>
			<input placeholder="确认密码" password v-model="txt4"></input>
		</block>
		<block v-if="lx==3">
			<input placeholder="请输入登录密码" password v-model="txt5"></input>
			<input placeholder="请输入新资金密码" password v-model="txt6"></input>
			<input placeholder="确认资金密码" password v-model="txt7"></input>
		</block>
		<view class="btn" @tap="bcBtn">
			保存
		</view>
	</view>
</template>

<script>
	const http = require('../../utils/http.js');
	export default {
		data() {
			return {
				lxTxt:null,
				lx:null,
				txt1:null,
				txt2:null,
				txt3:null,
				txt4:null,
				txt5:null,
				txt6:null,
				txt7:null
			}
		},
		onLoad(options) {
			this.lx=options.lx
			if(options.lx==1){
				this.lxTxt='修改昵称'
			}
			if(options.lx==2){
				this.lxTxt='修改密码'
			}
			if(options.lx==3){
				this.lxTxt='修改资金密码'
			}
		},
		methods: {
			bcBtn:function(){
				if(this.lx==1){
					if(!this.txt1){
						uni.showToast({
						  title: '请输入要修改昵称',
						  icon: 'none'
						});
						return false
					}
					http.post('/api/user/updateNickName',{nickNme:this.txt1}).then(res => {
						//console.log(res)
						uni.showToast({
						  title: res.message,
						  icon: 'none',
						  duration:1000
						});
						if (res.code == 200) {
							uni.setStorageSync('userInfo',res.result)
							setTimeout(function () {
							    uni.navigateBack({
							        delta: 1
							    });
							}, 1000);
						}
					})
				}
				if(this.lx==2){
					if(!this.txt2){
						uni.showToast({
						  title: '登录密码不能为空',
						  icon: 'none'
						});
						return false
					}
					if(!this.txt3 && !this.txt4){
						uni.showToast({
						  title: '密码和确认密码不能为空',
						  icon: 'none'
						});
						return false
					}
					if(this.txt3 != this.txt4){
						uni.showToast({
						  title: '密码和确认密码不一致',
						  icon: 'none'
						});
						return false
					}
					http.post('/api/user/updatePassword',{oldPassword:this.txt2,newPassword:this.txt3}).then(res => {
						//console.log(res)
						uni.showToast({
						  title: res.message,
						  icon: 'none',
						  duration:1000
						});
						if (res.code == 200) {
							setTimeout(function () {
							    uni.navigateBack({
							        delta: 1
							    });
							}, 1000);
						}
					})
				}
				if(this.lx==3){
					if(!this.txt5){
						uni.showToast({
						  title: '登录密码不能为空',
						  icon: 'none'
						});
						return false
					}
					if(!this.txt6 && !this.txt7){
						uni.showToast({
						  title: '密码和确认密码不能为空',
						  icon: 'none'
						});
						return false
					}
					if(this.txt6 != this.txt7){
						uni.showToast({
						  title: '密码和确认密码不一致',
						  icon: 'none'
						});
						return false
					}
					http.post('/api/user/updateSecurity',{oldPassword:this.txt5,security:this.txt6}).then(res => {
						//console.log(res)
						uni.showToast({
						  title: res.message,
						  icon: 'none',
						  duration:1000
						});
						if (res.code == 200) {
							setTimeout(function () {
							    uni.navigateBack({
							        delta: 1
							    });
							}, 1000);
						}
					})
				}
			}
		}
	}
</script>

<style>
	.tit{
		padding: 8vw;
		font-size: 7vw;
		color: #4CD964;
	}
	input{
		width: 84%;
		padding: 2vw 0;
		margin: 0 auto;
		border-bottom: 1px solid #F2F2F2;
	}
	.btn{
		width: 84%;
		padding: 4vw 0;
		font-size: 3.5vw;
		border-radius: 1.8vw;
		background-image: linear-gradient(45deg, #24EBA9, #10C7B2);
		color: #FFFFFF;
		text-align: center;
		margin: 0 auto;
		margin-top: 10vw;
	}
</style>
